<template>
    <div>
      <div class="searchBox">
        <div class="searchInputs">
          <el-input class="searchInput" v-model="key" style="width: 240px" placeholder="按关键字搜索" />
        </div>
        <el-button type="primary" @click="refresh">搜索</el-button>
      </div>
      <div class="table">
        <el-table :data="tableData" style="width: 100%;">
          <el-table-column fixed prop="date" label="Date" width="150" />
          <el-table-column prop="name" label="Name" width="120" />
          <el-table-column prop="state" label="State" width="120" />
          <el-table-column prop="city" label="City" width="120" />
          <el-table-column prop="address" label="Address" />
          <el-table-column prop="zip" label="Zip" width="120" />
          <el-table-column fixed="right" label="Operations" width="120">
            <template #default>
              <el-button link type="primary" size="small">Detail</el-button>
              <el-button link type="primary" size="small">Edit</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination 
        layout="prev, pager, next" 
         v-model:current-page="pageNum"
        v-model:page-size="pageSize" 
        :page-sizes="[100, 200, 300, 400]"
        @size-change="getList"
        @current-change="getList"
      :total="total" />
    </div>
  </template>
  
  <script>
  export default {
    name: 'userList',
    data(){
      return {
        tableData:[],
        key:'',
        total:0,
        pageNum:1,
        pageSize: 10
      }
    },
    methods:{
      refresh(){
        this.pageNum = 1
        this.getList()
      },
      async getList(){
        let res = await this.$get('/user/list',{
          key:this.key,
          pageNum:this.pageNum,
          pageSize:this.pageSize
        })
        this.total = res.total
        this.tableData = res.rows
      }
    },
    mounted(){
      this.getList()
    }
  }
  </script>
  <style scoped>
  .searchBox {
    margin-bottom: 20px;
    display: flex;
  }
  
  .searchInputs {
    margin-right: 16px;
  }
  
  .searchInput {
    margin-right: 16px;
  }
  
  .table {
    width: 100%;
  }
  </style>